package jok.thread;

public class DeadlockThread implements Runnable {

	private boolean flag;

	public DeadlockThread(boolean flag) {
		super();
		this.flag = flag;
	}

	@Override
	public void run() {
		if (flag) {
			synchronized (Lock.lock1) {
				System.out.println("线程1拿到lock1");
				synchronized (Lock.lock2) {
					System.out.println("线程1拿到lock2");
				}
			}
		} else {
			synchronized (Lock.lock2) {
				System.out.println("线程2拿到lock2");
				synchronized (Lock.lock1) {
					System.out.println("线程2拿到lock1");
				}
			}
		}
	}

}

class Lock {

	static Object lock1 = new Object();

	static Object lock2 = new Object();
}